<template>
	<div class="plrEmpty approval_detail">
		<h4 v-if="recordInfo.appName">驾驶人</h4>
		<p v-if="recordInfo.appName">{{recordInfo.appName}}</p>
		<h4>夜驾时段信息</h4>
		<p v-if="recordInfo">{{recordInfo.dateFrom}}-{{recordInfo.dateTo}}</p>
		<h4 class="mt10" v-if="recordInfo.applyConent || hasApply">夜驾理由</h4>
		<p class="Reason" v-if="recordInfo.applyConent">{{recordInfo.applyConent || '暂无'}}</p>
		<textarea class="has_border w100" v-if="hasApply" v-model.trim = "sendData"></textarea>
		<h4 v-if="recordInfo.repName">审批人</h4>
		<p>{{recordInfo.repName}}</p>

		<div class="text_right mt10" >
			<span class="button btn_small" :class="btn.btnClass" v-for="btn of submitBtn" @click="submitBtnOpt(btn)">{{btn.value}}</span>
			<!-- <span class="button btn_small btn_default">取消</span>
			<span class="button btn_small btn_pri">申请</span> -->
		</div>
	</div>
</template>
<script type="text/javascript">
	import approvalStyle from '../../assets/css/approval.scss'

	import getInterface from '../../assets/js/insterface'

	export default{
		data(){
			return{
				'sendData':"",
				'applyConent':"",
				'recordInfo':'',
				'submitBtn':[],
				'submitType':"",
				'hasApply':false

			}
		},
		mounted(){
			this.$el.parentElement.parentNode.style.background = '#fafafa';
			document.title="夜驾记录信息";
			this.pageInit();
		},
		methods:{
			pageInit(){
				let personType = this.$route.query.personType;
				let applyStatus = this.$route.query.applyStatus;

				let approvalDetailUrl = getInterface.getApprovalDetailUrl;

				let params = {
					id:this.$route.query.id
				}
				if(personType =="01"){//审核人
					this.hasApply = false;
					if(applyStatus=="01"){
						this.submitBtn=[
							{'value':"拒绝",'btnClass':'btn_orange'},
							{'value':"通过",'btnClass':'btn_pri'}
						]
					}
				}else if(personType =="02"){//驾驶人
					this.hasApply = false;

					if(applyStatus=="00"){
						this.hasApply = true;
						this.submitBtn=[
							{'value':"取消",'btnClass':'btn_default'},
							{'value':"申请",'btnClass':'btn_pri'}
						]
					}else if(applyStatus=="01"){
						this.submitBtn = []
					}
				}

				this.$http.post(approvalDetailUrl,params,{emulateJSON:true})
				.then((response)=>{
					console.log(response);
					if(response.data != null){
						this.recordInfo = response.data.resultData;
						this.applyConent = response.data.resultData.applyConent;
					}
				})
			},
			submitBtnOpt(btn){
				let vue = this;
				switch(btn.value){
					case "申请":
						this.submitType = "01";
						this.postData(vue.sendData);
						this.sendData="";
						break;
					case "取消":
						this.sendData="";
						break;
					case "通过":
						this.submitType = "02"
						this.postData(vue.applyConent);
						break;
					case "拒绝":
						this.submitType = "03"
						this.postData(vue.applyConent);
						break;
				}
			},
			postData(applyConent){
				let approvalSubmitUrl = getInterface.getApprovalSubmitUrl;

				let params = {
					'id':this.$route.query.id,
					"applyConent":applyConent,
					'empNum':this.$route.query.empNo,
					'submitType':this.submitType,
				}
				// console.log(params);
				this.$http.post(approvalSubmitUrl,params,{emulateJSON:true})
				.then((response)=>{
					console.log(response);
					let personType = this.$route.query.personType;
					let applyStatus = this.$route.query.applyStatus

					//申请
					if(personType =='02' && applyStatus =='00' && response.data.resultCode=="1"){
						alert("申请成功！");
						window.history.go(-1);
					}
					// console.log("personType:"+personType+
					// 	"applyStatus:"+applyStatus+
					// 	"response.data.resultCode:"+response.data.resultCode+
					// 	"this.submitType:"+this.submitType)
					//拒绝
					if(personType =='01' && applyStatus =='01' && response.data.resultCode=="1" && this.submitType=="03"){
						alert("已成功拒绝！");
						this.$router.go(-1);
					}
					//通过审核
					if(personType =='01' && applyStatus =='01' && response.data.resultCode=="1" && this.submitType=="02"){
						alert("审核成功！");
						this.$router.go(-1);
					}

				})

			}
		}
	}
</script>
